package com.spring.campus_express_delivery.service.serviceImpl;
import com.spring.campus_express_delivery.dao.ExpressTypeDao;
import com.spring.campus_express_delivery.entity.ExpressCompany;
import com.spring.campus_express_delivery.entity.ExpressType;
import com.spring.campus_express_delivery.entity.PageBean;
import com.spring.campus_express_delivery.service.ExpressTypeService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
@Transactional
public class ExpressTypeServiceImp implements ExpressTypeService {
        @Resource
       ExpressTypeDao expressTypeDao;
    @Override
    public PageBean<ExpressType> selectExpressWeightTypeByPage(int size, int page, String sort, String asc) {
        HashMap<String,Object> map = new HashMap<String,Object>();
        PageBean<ExpressType> pageBean = new PageBean<ExpressType>();
        //封装当前页数
        pageBean.setCurrPage(page);
        //封装页数大小
        pageBean.setPageSize(size);
        //封装排序字段
        pageBean.setPageSort(sort);
        //封装排序规则
        pageBean.setPageAsc(asc);

        //封装总记录数
        int totalCount = expressTypeDao.selectCountByExpressWeightType();
        pageBean.setTotalCount(totalCount);

        //封装总页数
        double tc = totalCount;
        Double num =Math.ceil(tc/size);//向上取整
        pageBean.setTotalPage(num.intValue());


        map.put("PageStart",(page-1)*size);
        map.put("PageSize", pageBean.getPageSize());
        map.put("PageSort", sort);
        map.put("PageAsc", asc);

        //封装每页显示的数据
        List<ExpressType> lists = expressTypeDao.selectExpressWeightTypeByPage(map);
        pageBean.setLists(lists);
        return pageBean;
    }

    @Override
    public int selectCountByExpressWeightType() {
        return expressTypeDao.selectCountByExpressWeightType();
    }

    @Override
    public void insertExpressWeightType(ExpressType expressType) {
        expressTypeDao.insertExpressWeightType(expressType);
    }

    @Override
    public ExpressType selectByExpressWeightId(int id) {
        return expressTypeDao.selectByExpressWeightId(id);
    }

    @Override
    public void updateExpressWeightType(ExpressType expressType) {
        expressTypeDao.updateExpressWeightType(expressType);
    }

    @Override
    public void deleteExpressWeightById(Integer id) {
        expressTypeDao.deleteExpressWeightById(id);
    }

    @Override
    public ExpressType selectByExpressWeightType(String expressWeightType) {
        return expressTypeDao.selectByExpressWeightType(expressWeightType);
    }


//    //根据订单重量类型查询订单类型编号
//    @Override
//    public ExpressType selectExpressWeightType(String expressWeightType){
//        return expressTypeDao.selectExpressWeightType(expressWeightType);
//    }
//
//    @Override
//    public ExpressType selectOrdersByOutAddress(String outAddress) {
//        return expressTypeDao.selectOrdersByOutAddress(outAddress);
//    }
//    @Override
//    public ExpressType selectOrdersByServiceAddress(String serviceAddress) {
//        return expressTypeDao.selectOrdersByServiceAddress(serviceAddress);
//    }
}
